Ext.define('DragonApp.view.cron.Controller', {
    extend: 'DragonApp.view.foundation.ViewController',

    alias: 'controller.cron',
    /**
     * 回车搜索
     * @param    {[type]} field [description]
     * @param    {[type]} e [description]
     * @param    {[type]} options [description]
     * @return   {[type]}
     */
    onTextFieldSpecialKey: function(field, e, options) {
        if (e.getKey() === e.ENTER) {
            this.onSubmitClick();
        }
    },
    /**
     * 查询任务
     * @param    {[type]} button [description]
     * @param    {[type]} e [description]
     * @param    {[type]} options [description]
     * @return   {[type]}
     */
    onSubmitClick: function(button, e, options) {
        var me = this;
        var form = this.getView().getForm();

        if (!form.isValid()) return;

        var formValue = form.getValues();

        var grid = Ext.ComponentQuery.query('crongrid')[0];
        var store = grid.getStore();

        store.load({
            params: formValue,
            scope: this,
            callback: function(records, operation, success) {
                if (success == false) {
                    store.removeAll();
                }
            }
        });
    },
    //批量删除
    onBatDelete: function() {

        var grid = this.getView();
        var url = DragonApp.ux.config.Config.getUrl('/index/Cron/batDelete/');

        this.onBatDeleteExec(grid,url);
    },
    /**
     * 类型渲染
     * @param    {[type]} value [description]
     * @return   {[type]}
     */
    typeRender: function(value) {
        switch (value) {
            case 0:
                return '留存计算';
            case 1:
                return '账号解封';
        }
    },
    /**
     * 备注渲染
     * @param    {[type]} value 字段值
     * @return   {[type]}
     */
    commentsRender: function(value) {
        switch (value) {
            case 'terminate':
                return '任务终止';
            default:
                return '';
        }
    },
    /**
     * 刷新服务器
     * @param    {[type]} button [description]
     * @param    {[type]} e [description]
     * @param    {[type]} options [description]
     * @return   {[type]}
     */
    onRefresh: function(button, e, options) {

        var store = Ext.data.StoreManager.lookup('cronStore');
        store.loadPage(1);
    }
});